cmake_minimum_required(VERSION 3.14)

project(ukui-system-tray)
set(VERSION_MAJOR 1)
set(VERSION_MINOR 0)
set(VERSION_MICRO 0)
set(UKUI_SYSTEM_TRAY_VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_MICRO})

set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

find_package(QT NAMES Qt6 Qt5 COMPONENTS Core Gui Widgets Quick REQUIRED)
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Core Gui Widgets Quick REQUIRED)
find_package(ukui-panel-framework)

set(PROJECT_SOURCES
        plugin/system-tray-plugin.h plugin/system-tray-plugin.cpp
        plugin/tray-icon-items-model.h plugin/tray-icon-items-model.cpp
        plugin/tray-icon-item.h plugin/tray-icon-item.cpp
)

include_directories(${CMAKE_SOURCE_DIR}/status-notifier-host)

if(${QT_VERSION_MAJOR} GREATER_EQUAL 6)
    add_library(${PROJECT_NAME} SHARED MANUAL_FINALIZATION ${PROJECT_SOURCES})

else()
    add_library(${PROJECT_NAME} SHARED ${PROJECT_SOURCES})
endif()

target_compile_definitions(${PROJECT_NAME}
        PRIVATE $<$<OR:$<CONFIG:Debug>,$<CONFIG:RelWithDebInfo>>:QT_QML_DEBUG>
)

target_link_libraries(${PROJECT_NAME}
        PRIVATE
        Qt${QT_VERSION_MAJOR}::Core
        Qt${QT_VERSION_MAJOR}::Quick
        Qt${QT_MAJOR_VERSION}::Gui
        Qt${QT_VERSION_MAJOR}::Widgets
        ukui-sni-host
        ukui-panel-framework
)

install(DIRECTORY "widget/" DESTINATION "/usr/share/ukui-panel/widgets/org.ukui.systemTray")
install(FILES "plugin/qmldir" DESTINATION "/usr/lib/${CMAKE_LIBRARY_ARCHITECTURE}/qt5/qml/org/ukui/systemTray")
install(TARGETS ${PROJECT_NAME} LIBRARY DESTINATION  "/usr/lib/${CMAKE_LIBRARY_ARCHITECTURE}/qt5/qml/org/ukui/systemTray")
